﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using TookKit.Mvvm.Extensions;
using TookKit.Mvvm.Interfaces;

namespace TookKit.Mvvm
{
    public abstract class ApplicationBase : Application
    {
        public Container Container { get; } = Container.Default;

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);



            Initialize();//内部初始化工作
        }

        private void Initialize()
        {
            //配置模块目录
            Container.ModuleManager.ModuleCatalog = SetModuleCatalog();

            //手动增加模块
            ConfigureModules(Container.ModuleManager);

            //注册模块 + 初始化模块
            InitializeModules();


            //注册类型

            //创建主窗体

            MainWindow = CreateShell();
            MainWindow.Show();

            //显示主窗体
        }

        /// <summary>
        /// 创建主窗体
        /// </summary>
        /// <returns></returns>
        public abstract Window CreateShell();

        public virtual string SetModuleCatalog(string moduleCatalog = @"./Modules")
        {
            return moduleCatalog;
        }

        /// <summary>
        /// 手动增加模块
        /// </summary>
        /// <param name="moduleManager"></param>
        public virtual void ConfigureModules(IModuleManager moduleManager)
        {

        }

        /// <summary>
        /// 注册模块 + 初始化模块
        /// </summary>
        public virtual void InitializeModules()
        {
            Container.InitializeModules();
        }
    }
}
